<?php
namespace Home\Controller;
use Think\Controller;
class ipController extends Controller {
    public function index(){
        $ip  = get_client_ip();
        if($ip == '0.0.0.0'){
            $ip = '203.34.5.66';
        }

        $ch = curl_init();
        $url = 'http://apis.baidu.com/apistore/iplookupservice/iplookup?ip='.$ip;
        $header = array(
            'apikey: 19dd4d1483bc05be691a553153bc0d7e',
        );
        // 添加apikey到header
        curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // 执行HTTP请求
        curl_setopt($ch , CURLOPT_URL , $url);
        $res = curl_exec($ch);
        $res = json_decode($res);
        $area = $res->retData->country.'-'.$res->retData->province.'-'.$res->retData->city.'-'.$res->retData->district.'-'.$res->retData->carrier;

        $data['ip'] = $ip;
        $data['area'] = $area;
        $data['page'] = '';
        $data['time'] = time();
        M('logindata')->add($data);
    }
}

?>